const options = {
  debug: process.env.NODE_ENV === "development" ? true : false,
};
export const setOptions = (opts: { debug: boolean }) => {
  Object.assign(options, opts);
};

const colorfulConsole = (style = "", msg) => {
  console.log("%c%s", style, msg);
};

const proxy = (style, defaultTitle, title, args: any[]) => {
  if (options.debug) {
    if (!args) {
      colorfulConsole(style, defaultTitle);
      console.log(title);
      return;
    }
    colorfulConsole(style, title);
    console.log(...args);
  }
};

function printError(title, ...args: any[]) {
  proxy("color: #fff;background:red;", "Error:", title, args);
}

function printInfo(title, ...args) {
  proxy("color: #fff;background:#1890ff;", "Info:", title, args);
}

function printWarning(title, ...args) {
  proxy("color: #fff;background: #ffda0e;", "Warning:", title, args);
}

function printSuccess(title, ...args) {
  proxy("color: #fff;background: #52c41a;", "Success:", title, args);
}

const print = {
  error: printError,
  info: printInfo,
  warn: printWarning,
  warning: printWarning,
  success: printSuccess,
  setOptions,
};

export default print;
